package action;

import com.opensymphony.xwork2.ActionContext;
import lombok.Data;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import pojo.MedicalAdvice;
import service.MedicalAdviceService;
import util.GsonUtil;

import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.Soundbank;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@Data
public class MedicalAdviceAction {
    @Autowired
    private MedicalAdviceService service;

    private MedicalAdvice medicalAdvice;

    public String queryDetais(){
        List<MedicalAdvice> medicalAdvices = service.queryByMedical(medicalAdvice);
        ActionContext.getContext().getSession().put("meds", medicalAdvices);
        return "success";
    }

    public void queryByYz() throws Exception {
        List<MedicalAdvice> medicalAdvices = service.queryByYz(medicalAdvice);
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        out.print(GsonUtil.toJson(medicalAdvices));
    }
    public String addMed(){
        service.addMed(medicalAdvice);
        return "successs";
    }
    public String updateMed(){
        service.updateMed(medicalAdvice);
        return "successs";
    }
}
